//
//  Macro
//  TSP
//
//  Created by 周俊 on 14-6-16.
//
//

#ifndef TSP_MACRO_H
#define TSP_MACRO_H

//name space
#define TSP_NS_START namespace TSP {
#define TSP_NS_END }

//safe delete
#define TSP_SAFE_RELEASE(p) if(p){p->release(); p = nullptr;}
#define TSP_SAFE_DELETE(p) if(p){delete p; p = nullptr;}
#define TSP_SAFE_DELETE_ARRAY(p) if(p){delete [] p ; p = nullptr;}

//disallow copy and assign
#define TSP_DISALLOW_COPY_AND_ASSIGN(TypeName) \
    TypeName(const TypeName&){} \
    void operator=(const TypeName&){}

//create std::bind functions
#define TSP_CREATE_FUNC_0(CLASSFUNC, CLASSPTR) std::bind(CLASSFUNC, CLASSPTR)
#define TSP_CREATE_FUNC_1(CLASSFUNC, CLASSPTR) std::bind(CLASSFUNC, CLASSPTR, std::placeholders::_1)
#define TSP_CREATE_FUNC_2(CLASSFUNC, CLASSPTR) std::bind(CLASSFUNC, CLASSPTR, std::placeholders::_1, std::placeholders::_2)
#define TSP_CREATE_FUNC_3(CLASSFUNC, CLASSPTR) std::bind(CLASSFUNC, CLASSPTR, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)

//lower bytes and higher bytes
#define TSP_LOW_16_8(a) ( a & 0xFF)
#define TSP_LOW_32_16(a) ( a & 0xFFFF )
#define TSP_LOW_64_32(a) ( a & 0xFFFFFFFF )
#define TSP_HIGH_16_8(a) (( a >> 8 )& 0xFF)
#define TSP_HIGH_32_16(a) (( a >> 16 )& 0xFFFF)
#define TSP_HIGH_64_32(a) (( a >> 32 )& 0xFFFFFFFF)
#define TSP_COMBINE_8_16(a,b)   (((int16_t)a) << 8 | ((int16_t)b))
#define TSP_COMBINE_16_32(a,b)   (((int32_t)a) << 16 | ((int32_t)b))
#define TSP_COMBINE_32_64(a,b)   (((int64_t)a) << 32 | ((int64_t)b))

#endif /*(TSP_MACRO_H)*/
